package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0232.java
 * @Author : WangRuoyu
 * @Date 2023/11/9 16:31
 */


public class Q0232 {

    List<Integer> s1 = new ArrayList<>();
    List<Integer> s2 = new ArrayList<>();
    int count = 0;
    boolean flag = true;

    //    public MyQueue() {
    public Q0232() {

    }

    public void push(int x) {
        if (!flag) {
            flag = true;
            for (int i = s2.size() - 1; i >= 0; i--) {
                s1.add(s2.remove(s2.size() - 1));
            }
        }
        s1.add(x);
        count++;
    }

    public int pop() {
        if (flag) {
            flag = false;
            for (int i = s1.size() - 1; i >= 0; i--) {
                s2.add(s1.remove(s1.size() - 1));
            }
        }
        count--;
        return s2.remove(s2.size() - 1);
    }

    public int peek() {
        return flag ? s1.get(0) : s2.get(s2.size() - 1);
    }

    public boolean empty() {
        return count == 0;
    }

    public static void main(String[] args) {
        Q0232 sl = new Q0232();
        sl.push(1);
        sl.push(2);
        System.out.println(sl.pop());
    }
}